package com.trkj.service.lzs;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.trkj.pojo.ProjectTemplate;
import com.trkj.pojo.Recruitprocess;
import com.trkj.pojo.Salary;
import com.trkj.pojo.SalaryAccount;
import com.trkj.pojo.SocialAccount;
import com.trkj.pojo.SocialLeixing;
import com.trkj.pojo.SocialSecurity;
import com.trkj.service.ServiceException;
import com.trkj.vo.PayrollVo;
import com.trkj.vo.payVO;
import com.trkj.dao.lzs.PayrollDao;
import com.trkj.dao.lzs.SalaryAccountDao;
@Service
public class PayrollService {
	@Autowired
	private  PayrollDao PayrollDao;
	@Autowired
	private   SalaryAccountDao SalaryAccountDao;
	   //查询所有
		public  List<Salary>  PayrollAccount(){
		   return (List<Salary>) PayrollDao.findAll();
		}
		
		//添加
		public void tj(String salaryName ,String salsryBeizhu,String salsrySpz,Timestamp salsryPzdate,Timestamp salsryShdate ,BigDecimal salaryNumberEmployees) {
			try {
				Salary ab= new Salary();
				ab.setSalaryName(salaryName);
				ab.setSalsryBeizhu(salsryBeizhu);
				ab.setSalsryPzdate(salsryPzdate);
				ab.setSalsrySpz(salsrySpz);
				ab.setSalsryShdate(salsryShdate);
				ab.setSalaryNumberEmployees(salaryNumberEmployees);
				PayrollDao.save(ab);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
		//模糊查询
		//根据姓名查找
		public  List<Salary> queryByName (String  text){
		
			return PayrollDao.queryByName("%" + text + "%");
		}
		  //编辑  
	     public   void lzs_Edit( long salaryId ,BigDecimal salsryState,BigDecimal salaryNumberEmployees,BigDecimal salsrySum, String salsryPerson,String salaryName ,String salsryBeizhu,String salsrySpz,Timestamp salsryPzdate,Timestamp salsryShdate) {
	    	    Salary edit =PayrollDao.findOne(salaryId);
	    	    edit.setSalaryName(salaryName);
	    	    edit.setSalaryNumberEmployees(salaryNumberEmployees);
	    	    edit.setSalsryBeizhu(salsryBeizhu);
	    	    edit.setSalsryPerson(salsryPerson);
	    	    edit.setSalsryPzdate(salsryPzdate);
	    	    edit.setSalsryShdate(salsryShdate);
	    	    edit.setSalsrySpz(salsrySpz);
	    	    edit.setSalsryState(salsryState);
	    	    edit.setSalsrySum(salsrySum);
	    	   PayrollDao.save(edit);
	     }
	     
	     public Salary chun1(Long salaryId) {
	    	 return PayrollDao.findOne(salaryId);
	 		
	     }
	 	//删除
		 public boolean dltRe(Long salaryId) {
		 		if(PayrollDao.exists(salaryId)){
		 			PayrollDao.delete(salaryId);
		 			 return true;
		 		}
		 		return false;		
	
		 }
		 //多表查询
	     public List<PayrollVo> selcet_Salary(){
	 		List<PayrollVo> vo = new ArrayList();
	 		List<Object[]> obj= PayrollDao.find_payroll();
	 		for (Object[] objects : obj) {
	 			PayrollVo vof = new PayrollVo();
	 			  Salary      p  = (Salary) objects[0];
	 			  SalaryAccount s = (SalaryAccount) objects[1];
	 			if(s!=null) {
	 				vof.setAccountId(s.getAccountId());
	 			
	 			}
	 			if(p!=null){
	 				vof.setSalaryName(p.getSalaryName());
	 			}
	 		        vof.setAccountName(s.getAccountName());
	 				vof.setSalaryId(p.getSalaryId());
	 				vof.setSalaryNumberEmployees(p.getSalaryNumberEmployees());
	 				vof.setSalsrySum(p.getSalaryNumberEmployees());
	 			
	 				vo.add(vof);
	 		}
	 		return vo;
	 	}
	     
	 	/**
			 * 新增
			 * @param s
			 */
		public void add_Payr(Salary Social,Long accountId ){
				try {
					Salary sl = new Salary();
					/* sl.setSecurityEnddate(Social.getSecurityEnddate());
					 sl.setSecurityStartdate(Social.getSecurityStartdate());
					 sl.setSecurityName(Social.getSecurityName());
					 09sl.setSecurityNumberEmployees(Social.getSecurityNumberEmployees());*/
					
					System.out.println(accountId);
					System.out.println(Social);
					
					SalaryAccount soc = SalaryAccountDao.findOne(accountId);
					System.out.println(soc);
				    sl.setSalaryNumberEmployees(Social.getSalaryNumberEmployees());
					sl.setSalaryName(Social.getSalaryName());
					sl.setSalsrySum(Social.getSalsrySum());
	          	sl.setSalaryAccount(soc);
					
					Social.setSalaryAccount(soc);
					PayrollDao.save(sl);
				} catch (Exception e) {
					e.printStackTrace();
					throw new ServiceException(e);
				}
			}

}
